var express = require('express');
var router = express.Router();
var userRouter = require('./userRouter')
var newsRouter = require('./newsRouter')
var doctorsRouter = require('./doctorsRouter')
var patientsRouter = require('./patientsRouter')

//判断是否符合条件进入后台
function permission(req,res,next){
  if(req.session.username == undefined){
    //尚未登陆
    res.render('info/info',{
      title:"尚未登陆",
      content:"请重新登录",
      href:"/rl/login",
      hrefTxt:"登录页"
    })
  }else{
    next()
  }
}

/* GET users listing. */
router.get('/', permission,function(req, res, next) {
  //console.log(req.session)
  res.render('admin/index',{username:req.session.username});
});

//新闻管理 
router.use('/news', newsRouter);

//医生管理
router.use('/doctors', doctorsRouter);

//患者管理
router.use('/patients', patientsRouter);

//后台的用户管理
router.use('/user', userRouter);

module.exports = router;
